package com.ms.util;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;

public class ExtLimit {
	private Integer limit;//显示记录数
	private Integer start;//开始
	private Integer page;
	private String sort;//排序列
	private String dir;//排序方式 ASC DESC
	
	private String exp_name;//导出文件名称
	private String exp_type;//导出文件类型
	private String exp_column_names;//导出头信息
	private String exp_column_indexs;//导出列字段
	
	public Integer getPage() {
		return page;
	}
	public void setPage(Integer page) {
		this.page = page;
	}
	public Integer getLimit() {
		return limit;
	}
	public void setLimit(Integer limit) {
		this.limit = limit;
	}
	public Integer getStart() {
		if(start == null && page != null) {
			start = (page - 1) * limit;
		}
		else if(start == null && page == null) {
			start = 0;
		}
		return start;
	}
	public void setStart(Integer start) {
		this.start = start;
	}
	public String getDir() {
		return dir;
	}
	public void setDir(String dir) {
		this.dir = dir;
	}
	public String getSort() {
		
		//如下是特殊处理sencha touch传的排序参数，和Ext的有些区别
		//sort不为空但是dir为空，说明是sencha touch store传的参数
		if(!StringUtils.isEmpty(sort) && StringUtils.isEmpty(dir)) {
			JSONArray sortArr = JSONArray.fromObject(sort);
			JSONObject obj = sortArr.getJSONObject(0);//目前只处理单列排序
			sort = obj.getString("property");
			dir = obj.getString("direction");
		}
		
		return sort;
	}
	public void setSort(String sort) {
		this.sort = sort;
	}
	public String getExp_name() {
		return exp_name;
	}
	public void setExp_name(String expName) {
		exp_name = expName;
	}
	public String getExp_type() {
		return exp_type;
	}
	public void setExp_type(String expType) {
		exp_type = expType;
	}
	public String getExp_column_names() {
		return exp_column_names;
	}
	public void setExp_column_names(String expColumnNames) {
		exp_column_names = expColumnNames;
	}
	public String getExp_column_indexs() {
		return exp_column_indexs;
	}
	public void setExp_column_indexs(String expColumnIndexs) {
		exp_column_indexs = expColumnIndexs;
	}
}
